﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using BrnMall.Core;
using BrnMall.Manager.Domain.Distribution;
using BrnMall.Web.Framework;
using PetaPoco;

namespace BrnMall.Web.StoreAdmin.Models
{
    public class DisGradeListModel
    {
        public List<DisGradeModel> DisGradeList { get; set; }
    }

    public class DisGradeModel
    {
        public int Id { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        [Required(ErrorMessage = "名称不能为空")]
        [StringLength(30, ErrorMessage = "名称长度不能大于30")]
        public string Name { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        
        public string Description { get; set; }
        /// <summary>
        /// 佣金满足点
        /// </summary>
        [Required(ErrorMessage = "佣金满足点不能为空")]
        [Range(0, int.MaxValue, ErrorMessage = "佣金满足点必须大于0的整数")]
        public int BrokerageLimit { get; set; }
        /// <summary>
        /// 成交店铺佣金奖励
        /// </summary>
        [Required(ErrorMessage = "成交店铺佣金奖励不能为空")]
        [Range(0, int.MaxValue, ErrorMessage = "成交店铺佣金奖励必须大于0的整数")]
        public int FirstBrokerageRise { get; set; }
        /// <summary>
        /// 上一级成交店铺奖励
        /// </summary>
        [Required(ErrorMessage = "上一级成交店铺奖励不能为空")]
        [Range(0, int.MaxValue, ErrorMessage = "上一级成交店铺奖励必须大于0的整数")]
        public int SecondBrokerageRise { get; set; }
        /// <summary>
        /// 上二级成交店铺奖励
        /// </summary>
        [Required(ErrorMessage = "上二级成交店铺奖励不能为空")]
        [Range(0, int.MaxValue, ErrorMessage = "上二级成交店铺奖励必须大于0的整数")]
        public int ThirdBrokerageRise { get; set; }
        /// <summary>
        /// 是否默认
        /// </summary>
        [Required(ErrorMessage = "是否默认")]
        public bool IsDefault { get; set; }
        /// <summary>
        /// 类型0：分销商，1：代理商
        /// </summary>
        public int GradeType { get; set; }

       
    }

    #region 分销商
    public class DistributorListModel
    {
        public IList<DistributorViewModel> DistributorList { get; set; }
        public int GradeId { get; set; }
        public string DisStoreName { get; set; }
        public int OrdersTotalStart { get; set; }
        public int OrdersTotalEnd { get; set; }
        public IList<SelectListItem> DisGrades { get; set; }
        public PageModel PageModel { get; set; }
    }

    public class DistributorViewModel
    {
        public int Id { get; set; }
        /// <summary>
        /// 用户ID
        /// </summary>
        public PartUserInfo User { get; set; }
        /// <summary>
        /// 店铺ID
        /// </summary>
        public int StoreId { get; set; }
        /// <summary>
        /// 显示Logo
        /// </summary>
        public string ShowLogo { get; set; }

        /// <summary>
        /// 上级总代理商ID
        /// </summary>
        public Distributor Agent { get; set; }
        /// <summary>
        /// 等级
        /// </summary>
        public DisGrade DisGrade { get; set; }

        /// <summary>
        /// 上级分销商ID
        /// </summary>
        public int ParentId { get; set; }
        /// <summary>
        /// 分销等级
        /// </summary>
        public int DisLevel { get; set; }

        /// <summary>
        /// 路径
        /// </summary>
        public string Path { get; set; }
        /// <summary>
        /// 订单总额
        /// </summary>
        public decimal OrdersTotal { get; set; }
        /// <summary>
        /// 订单数量
        /// </summary>
        public int OrdersCount { get; set; }
        /// <summary>
        /// 佣金额度
        /// </summary>
        public decimal AccountBalance { get; set; }
        /// <summary>
        /// 历史提现额度
        /// </summary>
        public decimal RequestBalance { get; set; }
        /// <summary>
        /// 待发放金额
        /// </summary>
        public decimal PendingBalance { get; set; }
        /// <summary>
        /// 是否总代理，总代理提成所有分销商额度
        /// </summary>
        public int IsAgent { get; set; }

        /// <summary>
        /// 状态0:待审核，1：已审核，2：已关闭
        /// </summary>
        public int Status { get; set; }

        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 分销店铺名称
        /// </summary>
        public string DisStoreName { get; set; }
        /// <summary>
        /// 联系人
        /// </summary>
        public string LinkMan { get; set; }
        /// <summary>
        /// 联系电话
        /// </summary>
        public string PhoneNumber { get; set; }
        /// <summary>
        /// 提现记录
        /// </summary>
        public IList<BrokerageRequest> BrokerageRequest { get; set; }
        /// <summary>
        /// 提现记录分页
        /// </summary>
        public PageModel PageModel { get; set; }
        /// <summary>
        /// 我的团队分页
        /// </summary>
        public PageModel TeamPageModel { get; set; }
        /// <summary>
        /// 团队列表
        /// </summary>
        public IList<DistributorViewModel> TeamList { get; set; }


        /// <summary>
        /// 
        /// </summary>
        public DistributorViewModel()
        {
            Id = 0;

            StoreId = 0;

            ParentId = 0;
            Path = string.Empty;
            OrdersTotal = OrdersCount = 0;
            AccountBalance = RequestBalance = PendingBalance = IsAgent = Status = 0;
            ShowLogo = string.Empty;
            CreateTime = new DateTime(1900, 1, 1);
            DisStoreName = LinkMan = PhoneNumber = string.Empty;
            BrokerageRequest = new List<BrokerageRequest>();
            TeamList=new List<DistributorViewModel>();
        }
    }

    public class DistributorEditModel
    {
        public int Id { get; set; }
        public string ShowLogo { get; set; }
        [Required]
        [DisplayName("联系人")]
        public string LinkMan { get; set; }
        [Required]
        [DisplayName("分销商名称")]
        public string DisStoreName { get; set; }
        [Required]
        [DisplayName("联系电话")]
        public string PhoneNumber { get; set; }
    }


    #endregion
    #region 代理商
    public class AgentListModel
    {
        public IList<AgentViewModel> AgentList { get; set; }
        public int GradeId { get; set; }
        public string DisStoreName { get; set; }
        public int OrdersTotalStart { get; set; }
        public int OrdersTotalEnd { get; set; }
        public IList<SelectListItem> DisGrades { get; set; }
        public PageModel PageModel { get; set; }
    }
    public class OpenAgentListModel
    {
        /// <summary>
        /// 分页对象
        /// </summary>
        public PageModel PageModel { get; set; }
        /// <summary>
        /// 用户列表
        /// </summary>
        public DataTable UserList { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 用户邮箱
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 用户手机
        /// </summary>
        public string Mobile { get; set; }
    }
    public class AgentViewModel
    {
        public int Id { get; set; }
        /// <summary>
        /// 用户ID
        /// </summary>
        public PartUserInfo User { get; set; }
        /// <summary>
        /// 店铺ID
        /// </summary>
        public int StoreId { get; set; }
        /// <summary>
        /// 显示Logo
        /// </summary>
        public string ShowLogo { get; set; }

        /// <summary>
        /// 上级总代理商ID
        /// </summary>
        public Distributor Agent { get; set; }
        /// <summary>
        /// 等级
        /// </summary>
        public DisGrade DisGrade { get; set; }

        /// <summary>
        /// 上级分销商ID
        /// </summary>
        public int ParentId { get; set; }
        /// <summary>
        /// 分销等级
        /// </summary>
        public int DisLevel { get; set; }

        /// <summary>
        /// 路径
        /// </summary>
        public string Path { get; set; }
        /// <summary>
        /// 订单总额
        /// </summary>
        public decimal OrdersTotal { get; set; }
        /// <summary>
        /// 订单数量
        /// </summary>
        public int OrdersCount { get; set; }
        /// <summary>
        /// 佣金额度
        /// </summary>
        public decimal AccountBalance { get; set; }
        /// <summary>
        /// 历史提现额度
        /// </summary>
        public decimal RequestBalance { get; set; }
        /// <summary>
        /// 待发放金额
        /// </summary>
        public decimal PendingBalance { get; set; }
        /// <summary>
        /// 是否总代理，总代理提成所有分销商额度
        /// </summary>
        public int IsAgent { get; set; }

        /// <summary>
        /// 状态0:待审核，1：已审核，2：已关闭
        /// </summary>
        public int Status { get; set; }

        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 分销店铺名称
        /// </summary>
        public string DisStoreName { get; set; }
        /// <summary>
        /// 联系人
        /// </summary>
        public string LinkMan { get; set; }
        /// <summary>
        /// 联系电话
        /// </summary>
        public string PhoneNumber { get; set; }
        /// <summary>
        /// 提现记录
        /// </summary>
        public IList<BrokerageRequest> BrokerageRequest { get; set; }
        

        /// <summary>
        /// 提现记录分页
        /// </summary>
        public PageModel PageModel { get; set; }
        /// <summary>
        /// 团队分页
        /// </summary>
        public PageModel TeamPageModel { get; set; }

        public IList<AgentViewModel> TeamList { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public AgentViewModel()
        {
            Id = 0;

            StoreId = 0;

            ParentId = 0;
            Path = string.Empty;
            OrdersTotal = OrdersCount = 0;
            AccountBalance = RequestBalance = PendingBalance = IsAgent = Status= 0;
            ShowLogo = string.Empty;
            CreateTime = new DateTime(1900, 1, 1);
            DisStoreName = LinkMan = PhoneNumber = string.Empty;
            BrokerageRequest = new List<BrokerageRequest>();
            TeamList=new List<AgentViewModel>();
        }
    }

    public class AgentEditModel
    {
        public int Id { get; set; }
        public string ShowLogo { get; set; }
        [Required]
        [DisplayName("联系人")]
        public string LinkMan { get; set; }
        [Required]
        [DisplayName("分销商名称")]
        public string DisStoreName { get; set; }
        [Required]
        [DisplayName("联系电话")]
        public string PhoneNumber { get; set; }
    }
    #endregion
    #region 佣金明细

    public class BrokerageModel
    {
        public int Id { get; set; }
        /// <summary>
        /// 佣金结算给谁
        /// </summary>
        public int UserId { get; set; }

        public Distributor Distributor { get; set; }

        /// <summary>
        /// 店铺ID
        /// </summary>
        public int StoreId { get; set; }

        public string OrderNo { get; set; }
        /// <summary>
        /// 下单人
        /// </summary>
        public int TradeUserId { get; set; }

        /// <summary>
        /// 订单创建人
        /// </summary>
        public PartUserInfo TradeUser { get; set; }

        /// <summary>
        /// 结佣时间
        /// </summary>
        public DateTime TradeTime { get; set; }
        

        /// <summary>
        /// 结佣金额
        /// </summary>
        public decimal OrderAmount { get; set; }
        /// <summary>
        /// 佣金
        /// </summary>
        public decimal BrokerageAmount { get; set; }
        /// <summary>
        /// 费用类型0：成交返佣
        /// </summary>
        public int BrokerageType { get; set; }
        /// <summary>
        /// 状态0待审核，1，已审核，2，已拒绝
        /// </summary>
        public int Status { get; set; }
        /// <summary>
        /// 备注
        /// </summary>

        public string Remark { get; set; }
        /// <summary>
        /// 审核人
        /// </summary>
        public int ApprovedUserId { get; set; }
        /// <summary>
        /// 审核人
        /// </summary>
        public string ApprovedUserName { get; set; }
        /// <summary>
        /// 审核时间
        /// </summary>
        public DateTime ApprovedTime { get; set; }
        /// <summary>
        /// 分佣提成点%
        /// </summary>
        public int BrokerageRise { get; set; }
        public BrokerageModel()
        {
            Id =UserId=StoreId=TradeUserId= 0;
            OrderNo =string.Empty;
            TradeTime=new DateTime(1900,1,1);
            OrderAmount = BrokerageAmount= 0;
            BrokerageType = 0;
            Status = 0;
            Remark = string.Empty;
            ApprovedUserId = 0;
            ApprovedUserName = string.Empty;
            ApprovedTime=new DateTime(1900,1,1);
            BrokerageRise = 0;
        }
    }

    

    public class BrokerageListModel
    {
        public IList<BrokerageModel> BrokerageList { get; set; }
        
        public string DisStoreName { get; set; }
        public string TradeTimeStart { get; set; }
        public string TradeTimeEnd { get; set; }
        public string OrderNo { get; set; }
        public PageModel PageModel { get; set; }
    }

    #endregion
    #region 申请提现
    public class BrokerageRequestModel
    {
        public int Id { get; set; }
        /// <summary>
        /// 提现人
        /// </summary>
        public int UserId { get; set; }
        /// <summary>
        /// 分销商或者代理商
        /// </summary>
        public Distributor Distributor { get; set; }
        /// <summary>
        /// 请求订单号
        /// </summary>
        public string Brsn { get; set; }
        /// <summary>
        /// 提现人
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 提现类型0：微信企业转账
        /// </summary>
        public int RequestType { get; set; }
        /// <summary>
        /// 提现用户的平台OpenID
        /// </summary>
        public string RequestOpenId { get; set; }
        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime RequestTime { get; set; }
        /// <summary>
        /// 提现金额
        /// </summary>
        public decimal Amount { get; set; }

        /// <summary>
        /// 提现人真实姓名
        /// </summary>
        public string RequestUserRealName { get; set; }
        /// <summary>
        /// 提现银行账号
        /// </summary>
        public string RequestBankAccount { get; set; }
        /// <summary>
        /// 提现银行名称
        /// </summary>
        public string RequestBankName { get; set; }
        /// <summary>
        /// 联系电话
        /// </summary>
        public string PhoneNumber { get; set; }
        /// <summary>
        /// 状态0:待审核1：已审核，2：已拒绝
        /// </summary>
        public int Status { get; set; }
        /// <summary>
        /// 0：待发放，1：已发放
        /// </summary>
        public int PayStatus { get; set; }

        /// <summary>
        /// 审核人
        /// </summary>
        public int ApprovedUserId { get; set; }
        /// <summary>
        /// 审核人
        /// </summary>
        public string ApprovedUserName { get; set; }
        /// <summary>
        /// 审核时间
        /// </summary>
        public DateTime ApprovedTime { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// 打款时间
        /// </summary>
        public DateTime SendTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public BrokerageRequestModel()
        {
            Id = UserId = RequestType = 0;
            UserName = RequestOpenId =Brsn= string.Empty;
            RequestTime = new DateTime(1900, 1, 1);
            RequestUserRealName = RequestBankAccount = RequestBankName = PhoneNumber = string.Empty;
            Status = ApprovedUserId = 0;
            ApprovedUserName = string.Empty;
            ApprovedTime = SendTime = new DateTime(1900, 1, 1);
            Remark = string.Empty;
            Amount = PayStatus = 0;

        }
    }
    public class BrokerageRequestListModel
    {
        public IList<BrokerageRequestModel> BrokerageRequestList { get; set; }

        public string DisStoreName { get; set; }
        public string RequestTimeStart { get; set; }
        public string RequestTimeEnd { get; set; }
        public string SendTimeStart { get; set; }
        public string SendTimeEnd { get; set; }
        public PageModel PageModel { get; set; }
    }
    #endregion


}
